<?php

require_once 'Core/Form.php';

class Admin_Form_Login extends Core_Form
{
    /**
     * Initialize the form
     *
     * @return void
     */
    public function init()
    {
        parent::init();
        $view = $this->getView();

        // create new element
        $id = $this->createElement('hidden', 'id', array(
            'decorators'    => array('ViewHelper')
        ));

        // create new element
        $userName = $this->createElement('text', 'adminUsername', array(
            'label'         => $view->getTranslation('Username'),
            'required'      => true,
            'filters'       => array('StringTrim'),
            'validators'    => array(
                array('NotEmpty', true),
                array('StringLength', true, array(4, 20)),
                array('Regex', true, array(
                    'pattern'  => Model_User::USERNAME_REGEX,
                    'messages' => array('regexNotMatch' => Model_User::USERNAME_REGEX_NOTMATCH),
                )),
            ),
            'attribs'       => array('size' => 50),
            'errorMessages' => array('You must enter a valid username.'),
        ));

        // create new element
        $password = $this->createElement('password', 'adminPassword', array(
            'label'         => $view->getTranslation('Password'),
            'required'      => true,
            'filters'       => array('StringTrim'),
            'errorMessages' => array('You must enter your password.'),
        ));

        $submit = $this->createElement('submit', 'submitAdminLogin', array(
            'label'         => $view->getTranslation('Login'),
            'attribs'       => array('class' => 'submit'),
        ));

        // add the elements to the form
        $this->addElement($id)
             ->addElement($userName)
             ->addElement($password)
             ->addElement($submit);

        $this->setDecorators(array(
            'FormElements',
            'Form',
        ));

        $this->setDisplayGroupDecorators(array(
            'FormElements',
            'Fieldset',
        ));
    }
}